package com.cxk.hr.util;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

import com.cxk.hr.pojo.Employee;

/**
 * 密码加密类
 * 
 * @author 84157
 *
 */
public class PasswordEncryption {
	/**
	 * 密码加密方法
	 * 
	 * @param employee
	 * @return employee
	 */
	public static Employee encryption(Employee employee) {
		// 加密方式
		String hashAlgorithmName = "MD5";

		// 密码原值
		Object crdentials = employee.getPassword();

		// 以账号作为盐值(盐值为null时,返回的就是仅md5加密结果)
		ByteSource salt = ByteSource.Util.bytes(Integer.toString(employee.getEmployeeNumber()));

		// 加密1024次
		int hashIterations = 1024;

		// 加密加盐
		Object result = new SimpleHash(hashAlgorithmName, crdentials, salt, hashIterations);

		// 员工密码更新为加密加盐后的
		employee.setPassword(result.toString());
		return employee;
	}

}